package com.mer.controller;

import com.mer.entity.User;
import com.mer.entity.UserRole;
import com.mer.service.UserService;
import com.mer.vo.CommonResult;
import com.mer.vo.RoleVo;
import com.mer.vo.UserRoleVo;
import com.mer.vo.UserVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: IIPhase-project
 * @description:
 * @author: 冯彦凯
 * @create: 2021-10-20 19:13
 **/
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;
    @ApiOperation("查询所有的员工信息")
    @PostMapping("getAllUserByPage/{page}/{limit}")
    public CommonResult getAllUserByPage(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @RequestBody UserVo userVo
            ){
        return userService.getAllUserByPage(page, limit, userVo);
    }
    @ApiOperation("添加用户信息")
    @PostMapping("addUserByUser")
    public CommonResult addUserByUser(
            @RequestBody User user
            ){
        return userService.addUserByUser(user);
    }
    @ApiOperation("修改用户信息")
    @PostMapping("updateUserByUser")
    public CommonResult updateUserByUser(
            @RequestBody User user
    ){
        return userService.updateUserByUser(user);
    }
    @ApiOperation("根据ID修改用户的状态")
    @PostMapping("updateUserStatusById/{id}/{deleted}")
    public CommonResult updateUserStatusById(
            @PathVariable String id,
            @PathVariable Integer deleted
    ){
        return userService.updateUserStatusById(id, deleted);
    }

    @ApiOperation("根据ID删除信息")
    @DeleteMapping("deleteUserById/{id}")
    public CommonResult deleteUserById(
            @PathVariable String id
    ){
        return userService.deleteUserById(id);
    }

    @ApiOperation("根据用户id获取角色")
    @GetMapping("findRoleByUserId/{userId}")
    public CommonResult findRoleByUserId(
            @PathVariable String userId){
        return userService.findRoleByUserId(userId);
    }

    @ApiOperation("根据名称获取权限")
    @PostMapping("findRoleByRoleName/{page}/{limit}")
    public CommonResult findRoleByRoleName(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit,
            @RequestBody RoleVo roleVo){
        return userService.findRoleByRoleName(page, limit, roleVo);
    }

    @ApiOperation("用户管理的分配角色")
    @PostMapping("giveRoleToUser")
    public CommonResult giveRoleToUser(
            @RequestBody UserRoleVo userRoleVo
            ){
        return userService.giveRoleToUser(userRoleVo);
    }
}
